{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "功能：\n",
    "0.交互界面\n",
    "1.登录\n",
    "2.查询余额\n",
    "3.取钱\n",
    "4.存钱\n",
    "5.退出"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 登录\n",
    "def login():\n",
    "    '''\n",
    "    登录信息\n",
    "    '''\n",
    "    key_u = input('请输入用户名：')\n",
    "    key_p = input('请输入密码：')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "def check_balances():\n",
    "    '''\n",
    "    查询余额\n",
    "    '''\n",
    "    print('='*40)\n",
    "    print(' '*8,'账户余额为{:^9}元'.format(users_data[user_list[0]]['money']))\n",
    "    print('='*40)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "def withdrew():\n",
    "    '''\n",
    "    取钱\n",
    "    '''\n",
    "    key_m = float(input('请输入您要取款的金额：'))\n",
    "    \n",
    "    # 判断余额是否大于取款金额，是，执行取款\n",
    "    if users_data[user_list[0]]['money'] >= key_m:\n",
    "        users_data[user_list[0]]['money'] -= key_m\n",
    "        print('='*40)\n",
    "        print(' '*8,'您已成功取款{:^9}元'.format(key_m))\n",
    "        print('='*40)\n",
    "    else:\n",
    "        print('='*40)\n",
    "        print(' '*8,'余额不足')\n",
    "        print('='*40)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "def save():\n",
    "    '''\n",
    "    存钱\n",
    "    '''\n",
    "    key_m = float(input('请输入您要存款的金额：'))\n",
    "    users_data[user_list[0]]['money'] += key_m\n",
    "    print('='*40)\n",
    "    print(' '*8,'您已成功存款{:^9}元'.format(key_m))\n",
    "    print('='*40)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "def log_out():\n",
    "    '''\n",
    "    退出\n",
    "    '''\n",
    "    print('='*40)\n",
    "    print(' '*8,'谢谢使用！')\n",
    "    print('='*40)\n",
    "    user_list = []\n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入用户名：lisi\n",
      "请输入密码：1234\n",
      "============ 登录成功! ============\n",
      "============ 用户操作界面 ============\n",
      " 1. 查询余额      2. 取钱          \n",
      " 3. 存钱          4. 退出          \n",
      "========================================\n",
      "请输入对应选择4\n",
      "========================================\n",
      "         谢谢使用！\n",
      "========================================\n"
     ]
    }
   ],
   "source": [
    "# 字典写入，初始化账户信息\n",
    "users_data = [\n",
    "    {'name':'zhangsan','pw':'123','money':30000},\n",
    "    {'name':'lisi','pw':'1234','money':40000},\n",
    "    {'name':'wangwu','pw':'12345','money':50000}\n",
    "]\n",
    "\n",
    "\n",
    "# 控列表，存登录用户信息\n",
    "user_list = []\n",
    "def login():\n",
    "    '''\n",
    "    登录信息\n",
    "    '''\n",
    "    key_n = input('请输入用户名：')\n",
    "    key_p = input('请输入密码：')\n",
    "    # 遍历检查用户信息是否正确\n",
    "    for i,user_dict in enumerate(users_data):\n",
    "        if user_dict['name'] == key_n and user_dict['pw'] == key_p:\n",
    "            user_list.append(i)\n",
    "            user_list.append(user_dict['name'])\n",
    "            \n",
    "    if user_list != []:\n",
    "        print('='*12,'登录成功!','='*12)\n",
    "        print('='*12,'用户操作界面','='*12)\n",
    "        \n",
    "        while True:\n",
    "            print('{:1}{:<13}{:<15}'.format(' ','1. 查询余额','2. 取钱'))\n",
    "            print('{:1}{:<15}{:<15}'.format(' ','3. 存钱','4. 退出'))\n",
    "            print('='*40)\n",
    "            key = input('请输入对应选择')\n",
    "            # 根据输入值操作，执行对应操作\n",
    "            if key == '1':\n",
    "                check_balances()\n",
    "                input('请回车继续：')\n",
    "            elif key == '2':\n",
    "                withdrew()\n",
    "                input('请回车继续：')\n",
    "            elif key == '3':\n",
    "                save()\n",
    "                input('请回车继续：')\n",
    "            elif key == '4':\n",
    "                log_out()\n",
    "                break\n",
    "            else:\n",
    "                print('操作无效')\n",
    "                input('请回车继续：')\n",
    "        \n",
    "    else:\n",
    "        print('用户名或密码错误,请重新输入')\n",
    "        input('任意键返回：')\n",
    "        login()\n",
    "            #key = input('请输入对应选择')\n",
    "    # 根据输入值操作，执行对应操作\n",
    "            #if key == '1':\n",
    "#         else:\n",
    "#             print('用户名或密码错误')\n",
    "\n",
    "login()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
